package com.ly.hotel.spainterface.jxd.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RadioButton;
import android.widget.TextView;

import com.ly.hotel.R;

import java.util.List;

/**
 * Created by ThinkPad on 2018/3/26.
 */

public class JxdJSSexAdapter extends BaseAdapter {

    private Context context;
    private List<String> sexList;
    private int defaultPosition = 0;

    public JxdJSSexAdapter(Context context, List<String> sexList){
        this.context = context;
        this.sexList = sexList;
    }

    public void setDefaultPositon(int positon){
        defaultPosition = positon;
    }

    @Override
    public int getCount() {
        return sexList.size();
    }

    @Override
    public Object getItem(int position) {
        return sexList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = null;
        ViewHolder holder = null;
        if(convertView == null){
            view = LayoutInflater.from(context).inflate(R.layout.jxd_select_sex_item,parent,false);
            holder = new ViewHolder();
            holder.therapySex = view.findViewById(R.id.therapy_sex);
            holder.therapySexSelect = view.findViewById(R.id.therapy_sex_select);
            view.setTag(holder);
        }else{
            view = convertView;
            holder = (ViewHolder) view.getTag();
        }
        if(defaultPosition == position){
            holder.therapySexSelect.setChecked(true);
        }else{
            holder.therapySexSelect.setChecked(false);
        }
        String sex = sexList.get(position);
        holder.therapySex.setText(sex);
        return view;
    }

    class ViewHolder{
        TextView therapySex;
        RadioButton therapySexSelect;
    }
}
